package com.pucheng.bracelet.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import com.pucheng.bracelet.R
import com.pucheng.bracelet.app.util.click
import kotlinx.android.synthetic.main.dialog_birthday_select.*
import kotlinx.android.synthetic.main.dialog_time_select.*
import kotlinx.android.synthetic.main.dialog_time_select.tv_cancel
import kotlinx.android.synthetic.main.dialog_time_select.tv_done

class BirthdaySelectDialog(private val mContext: Context) :
    Dialog(mContext, R.style.DialogStyle) {

    private var onUserinfoSelectedListener: SelectUserInfoDialog.UserinfoDataSelectedListener? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_birthday_select)

        tv_cancel.click {
            dismiss()
        }
        tv_done.click {
            if (onUserinfoSelectedListener!= null){
                onUserinfoSelectedListener!!.onSelectItem("${wv_birthday.currentYear}-${wv_birthday.currentMonth}-${wv_birthday.currentDay}",0)
            }
            dismiss()
        }
//            wvAmpm.setOnItemSelectedListener { index ->
////                mViewModel.changeTime(apIndex = index)
//            }
//            wvHour.setOnItemSelectedListener { index ->
//                mViewModel.changeTime(hourIndex = index)
//            }
//            wvMinute.setOnItemSelectedListener { index ->
//                mViewModel.changeTime(minuteIndex = index)
//            }

        val window = window
        window!!.setGravity(Gravity.BOTTOM)
        val attributes = window.attributes
        window.attributes = attributes
        setCanceledOnTouchOutside(true)

        initWheel()
    }

    private fun initWheel() {
        wv_birthday.setYearFrame(1950,2100)
//        wv_birthday.selectedYear = 2021
        wv_birthday.setYearAndMonth(2021,3)
        wv_birthday.setOnDateSelectedListener { _, date ->  }
    }
    fun setOnItemSelectedListener(itemSelectedListener: SelectUserInfoDialog.UserinfoDataSelectedListener): BirthdaySelectDialog {
        this.onUserinfoSelectedListener = itemSelectedListener
        return this
    }
}